package com.leyou.gateway.config;


import com.leyou.auth.utils.RsaUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.context.properties.ConfigurationProperties;

import javax.annotation.PostConstruct;
import java.io.File;
import java.security.PublicKey;

//@Component
@ConfigurationProperties(prefix = "leyou.jwt")
public class JwtProperties {
    private String pubKeyPath; //公钥
    private String cookieName;
    private PublicKey publicKey;//公钥对象

    private final Logger log = LoggerFactory.getLogger(JwtProperties.class);

     @PostConstruct
    public void init() {
        try{
            File pubKey = new File(pubKeyPath);
            if (pubKey.exists()){
                this.publicKey=RsaUtils.getPublicKey(pubKeyPath);
            }
        }catch (Exception e){
            log.error("获取公钥失败",e);
            throw new RuntimeException();
        }
    }


    public String getPubKeyPath() {
        return pubKeyPath;
    }

    public void setPubKeyPath(String pubKeyPath) {
        this.pubKeyPath = pubKeyPath;
    }

    public PublicKey getPublicKey() {
        return publicKey;
    }



    public String getCookieName() {
        return cookieName;
    }

    public void setCookieName(String cookieName) {
        this.cookieName = cookieName;
    }


}
